//
//  OrderScoreCell.m
//  Pension
//
//  Created by  YIQI on 2019/4/2.
//  Copyright © 2019年  YIQI. All rights reserved.
//

#import "OrderScoreCell.h"
#import "GBStarRateView.h"
#import "YQGoodsOrderModel.h"
@interface OrderScoreCell ()<GBStarRateViewDelegate>

@property (nonatomic,strong)UILabel *contentLabel;

@end

@implementation OrderScoreCell
-(void)setItemModel:(YQGoodsOrderItemModel *)itemModel {
    _itemModel = itemModel;
    self.starRateView.currentStarRate = itemModel.starNum;
    self.hiddenButton.selected = itemModel.hiddenName;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 12,50, 20)];
        self.contentLabel.text = kYQLS(@"评价");
        self.contentLabel.textColor = kAPPMainTitleColor;
        self.contentLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.contentLabel];
        
        self.hiddenButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.hiddenButton.frame = CGRectMake(kYQPScreenWidth-120, 12, 100, 20);

        [self.hiddenButton setTitle:kYQLS(@"匿名评价") forState:UIControlStateNormal];
        [self.hiddenButton setTitleColor:[UIColor colorWithHexString:@"8f8f8f"] forState:UIControlStateNormal];
        [self.hiddenButton setTitleColor:kAPPThemeColor forState:UIControlStateSelected];
        [self.hiddenButton setImage:YQIMG(@"shopCar_select_d_icon") forState:(UIControlStateNormal)];
        [self.hiddenButton setImage:YQIMG(@"shopCar_select_s_icon") forState:(UIControlStateSelected)];
        [self.hiddenButton addTarget:self action:@selector(hiddenButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
        
        self.hiddenButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        self.hiddenButton.titleLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.hiddenButton];
        [self.contentView addSubview:self.starRateView];

    }
    return self;
}

-(void)hiddenButtonAction:(UIButton *)sender {
    sender.selected = !sender.selected;
    self.itemModel.hiddenName = sender.selected;
}

-(void)layoutSubviews {
    [super layoutSubviews];
    
}

- (GBStarRateView *)starRateView {
    if (!_starRateView) {
        _starRateView = [[GBStarRateView alloc] initWithFrame:CGRectMake(12, 56, 232, 32)];
        _starRateView.spacingBetweenStars = 18;
        _starRateView.starSize = CGSizeMake(32, 32);
        _starRateView.allowClickScore = YES;//是否可以点击
        _starRateView.numberOfStars = 5;
        _starRateView.style = GBStarRateViewStyleWholeStar;
        self.starRateView.currentStarRate = 0.0;
        _starRateView.delegate = self;
    }
    return _starRateView;
}
#pragma mark -- GBStarRateViewDelegate
#pragma mark -- GBStarRateViewDelegate
- (void)starRateView:(GBStarRateView *)starRateView didSelecteStarAtStarRate:(CGFloat)starRate {
    self.itemModel.starNum = starRate;
}

#pragma mark -- GBStarRateViewDelegate end

//- (void)createStarView {
//
//    CGFloat spaceWidth = (kDeviceWidth-kCurrentWidth(80)-kCurrentWidth(150))/4;
//    for (int i = 0; i < 5; i++) {
//        UIImageView *starImage = [[UIImageView alloc] initWithFrame:CGRectMake(kCurrentWidth(40)+(kCurrentWidth(30)+spaceWidth)*i, kCurrentWidth(56), kCurrentWidth(30), kCurrentWidth(30))];
//        starImage.image = [UIImage imageNamed:@"icon_order_eva_star"];
//        [self.contentView addSubview:starImage];
//    }
//}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
